// Test1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "test_instance.h"
#include "test_image_loader.h"
#include <chrono>
#include "Database.h"

using namespace std;

template< class T> void run_test()
{
	std::cout << std::endl << "*******************************" << std::endl;
	std::cout << "Initializing ..." << std::endl;
	auto start = std::chrono::high_resolution_clock::now();
	auto test = std::make_unique<T>();
	try
	{
		test->initialize();
	}
	catch (std::exception &ex)
	{
		std::cout << "EXCEPTION: " << ex.what() << std::endl;
	}
	auto stop = std::chrono::high_resolution_clock::now();
	std::cout << "The initialization took "
		<< std::chrono::duration<double, std::ratio<1, 1>>(stop - start).count()
		<< " seconds." << std::endl << std::endl;

	std::cout << std::endl << "Preparing to run the test ..." << std::endl;
	start = std::chrono::high_resolution_clock::now();
	try
	{
		test->prepare();
	}
	catch (std::exception &ex)
	{
		std::cout << "EXCEPTION: " << ex.what() << std::endl;
	}
	stop = std::chrono::high_resolution_clock::now();
	std::cout << "The preparation took " << std::chrono::duration<double, std::ratio<1>>(stop - start).count()
		<< " seconds." << std::endl << std::endl;

	std::cout << std::endl << "Running the test ..." << std::endl;
	start = std::chrono::high_resolution_clock::now();
	try
	{
		test->run();
	}
	catch (std::exception &ex)
	{
		std::cout << "EXCEPTION: " << ex.what() << std::endl;
	}
	stop = std::chrono::high_resolution_clock::now();
	std::cout << "Test run took " << std::chrono::duration<double, std::ratio<1>>(stop - start).count()
		<< " seconds." << std::endl << std::endl;

	std::cout << std::endl << "Cleaning up ..." << std::endl;
	start = std::chrono::high_resolution_clock::now();
	try
	{
		test->cleanup();
	}
	catch (std::exception &ex)
	{
		std::cout << "EXCEPTION: " << ex.what() << std::endl;
	}
	stop = std::chrono::high_resolution_clock::now();
	std::cout << "The cleanup took " << std::chrono::duration<double, std::ratio<1>>(stop - start).count()
		<< " seconds." << std::endl << std::endl;
}


void mnu_help()
{
	cout <<  "*********************************************" << endl
		<< "I\t - Run Instance Test" << endl
		<< "L\t - Image Load Test" << endl
		<< "Q\t - Quit" << endl << endl
		<< "*********************************************" << endl
		<< ">";
}

int main(int argc, char* argv[])
{
	char mnu_c = '\0';
	do
	{
		switch (mnu_c)
		{
		case 'I':
		case 'i': 
			run_test<test_instance>();
			break;
		case 'L':
		case 'l':
			run_test<test_image_loader>();
			break;
		}// switch
		mnu_help();
	}
	while (((mnu_c = std::cin.get()) != 'Q') && (mnu_c != 'q'));

	return 0;
}

